import { post } from '../request';
import type { UserInfo } from '@/store/modules/auth';

// 登录请求参数
export interface LoginParams {
  email: string;
  password: string;
  remember?: boolean;
}

// 注册请求参数
export interface RegisterParams {
  username: string;
  email: string;
  password: string;
  confirmPassword: string;
}

// 忘记密码请求参数
export interface ForgotPasswordParams {
  email: string;
}

// 重置密码请求参数
export interface ResetPasswordParams {
  token: string;
  password: string;
  confirmPassword: string;
}

// 登录响应数据
export interface LoginResponse {
  token: string;
  user: UserInfo;
}

// 认证API
export const authApi = {
  // 用户登录
  login: (params: LoginParams) => {
    return post<LoginResponse>('/auth/login', params);
  },

  // 用户注册
  register: (params: RegisterParams) => {
    return post<{ message: string }>('/auth/register', params);
  },

  // 忘记密码
  forgotPassword: (params: ForgotPasswordParams) => {
    return post<{ message: string }>('/auth/forgot-password', params);
  },

  // 重置密码
  resetPassword: (params: ResetPasswordParams) => {
    return post<{ message: string }>('/auth/reset-password', params);
  },

  // 刷新Token
  refreshToken: () => {
    return post<{ token: string }>('/auth/refresh-token');
  },

  // 获取用户信息
  getUserInfo: () => {
    return post<UserInfo>('/auth/user-info');
  },

  // 更新用户信息
  updateUserInfo: (params: Partial<UserInfo>) => {
    return post<UserInfo>('/auth/update-profile', params);
  },

  // 修改密码
  changePassword: (params: { oldPassword: string; newPassword: string; confirmPassword: string }) => {
    return post<{ message: string }>('/auth/change-password', params);
  },

  // 退出登录
  logout: () => {
    return post<{ message: string }>('/auth/logout');
  },
};